package com.jdzy.student.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdzy.model.student.dtos.EventAnnouncementsDto;
import com.jdzy.model.student.pojos.EventAnnouncements;
import com.jdzy.student.mapper.EventAnnouncementsMapper;
import com.jdzy.student.service.EventAnnouncementsService;
import org.springframework.beans.BeanUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class EventAnnouncementsImpl extends ServiceImpl<EventAnnouncementsMapper, EventAnnouncements> implements EventAnnouncementsService {


    private final EventAnnouncementsMapper eventAnnouncementsMapper;
    @Override
    public IPage<EventAnnouncements> getEventAnnouncementsPage(long current, long size) {
        LambdaQueryWrapper<EventAnnouncements> queryWrapper = new LambdaQueryWrapper<>();
        // 可以在这里添加任何需要的查询条件
        // queryWrapper.eq(JobPostings::getSomeField, someValue);
        return  eventAnnouncementsMapper.selectPage(new Page<>(current, size), queryWrapper);
    }

    @Override
    public void saveOrUpdateEvent(EventAnnouncementsDto eventAnnouncementsDto) {
      // 判断是否存在id，如果存在则为更新，否则为保存
        if (eventAnnouncementsDto.getId() != null) {
            // 更新操作
            EventAnnouncements eventAnnouncements = new EventAnnouncements();
            BeanUtils.copyProperties(eventAnnouncementsDto, eventAnnouncements); // 使用Spring的BeanUtils来复制属性
            eventAnnouncementsMapper.updateById(eventAnnouncements);
        } else {
            // 保存操作
            EventAnnouncements eventAnnouncements = new EventAnnouncements();
            BeanUtils.copyProperties(eventAnnouncementsDto, eventAnnouncements); // 使用Spring的BeanUtils来复制属性
            eventAnnouncementsMapper.insert(eventAnnouncements);
        }
    }
}
